'use strict';

/**
 * @name HeaderCtrl
 * @author Yud
 */

angular.module('metalabOperationApp').controller('NoteCtrl', ['$scope', '$rootScope', '$state', '$stateParams', 'MetaResources', 'MetaRemind', function($scope, $rootScope, $state, $stateParams, MetaResources, MetaRemind) {
    //样式
    var height = (parseInt(angular.element('.meta-sidebar').css("height")) - 300)/2;
    angular.element('.tab-note').css("height", height + "px");
    //数据
    $scope.noteCtrl = {
        demandNotes: [],
        techNotes: []
    };
    $scope.getNotesData = function(sort) {
        MetaResources.process.get({
                'id': $stateParams.id,
                '_embed': 'demandSideProcess,technologySideProcess,demand,demand.publisher,demand.leader,demand.projectManager,demand.verifier,technology.verifier,technology,technology.publisher,technology.leader,technology.projectManager,projectManager'
            },
            function(data) {
                MetaResources.note.query({
                        'user_id': data.demand.leader.id,
                        '_sort': sort,
                        'solutionProcessId': $stateParams.id
                    },
                    function(data) {
                        $scope.noteCtrl.demandNotes = data;
                    },
                    function(error) {
                        MetaRemind.serverError(error);
                    });
                MetaResources.note.query({
                        'user_id': data.technology.leader.id,
                        '_sort': sort,
                        'solutionProcessId': $stateParams.id
                    },
                    function(data) {
                        $scope.noteCtrl.techNotes = data;
                    },
                    function(error) {
                        MetaRemind.serverError(error);
                    });

            },
            function(error) {
                MetaRemind.serverError(error);
            });
    };
    $scope.init = function() {
        $scope.getNotesData('+created_at');
    };
    $scope.init();
}]);
